package net.adetech.crj.dao;

import net.adetech.crj.entity.Appointment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AppointmentMapper {

    @Insert("insert into crj_appointment (appointment_id, real_name, id_type, id_number, state, service_type,create_time, update_time, apply_user_id, hall_id, day_id, time_period, apply_id,phone_number) " +
            " values (SEQ_APPOINTMENT_ID.nextval, #{realName}, '1', #{idNumber}, #{state}, #{serviceType},#{createTime}, #{updateTime}, #{applyUserId}, #{hallId}, #{dayId}, #{timePeriod},#{applyId,jdbcType=NUMERIC},#{phoneNumber})")
    void insert(Appointment appointment);

    @Select("select t.*,h.hall_name from crj_appointment t,crj_hall h where t.hall_id = h.id(+) and t.apply_user_id = #{applyUserId}")
    List<Appointment> getAppointmentListByApplyUserId(String applyUserId);

    @Select("select t.*,h.hall_name from crj_appointment t ,crj_hall h where t.hall_id = h.id(+) and t.id_number = #{idNumber} and t.day_id= #{dayId} and state in ('1','2')")
    Appointment getAppointmentByIdNumber(@Param("idNumber") String idNumber,@Param("dayId") String dayId);

    @Select("select t.*,h.hall_name from crj_appointment t ,crj_hall h where t.hall_id = h.id(+) and t.appointment_id = #{appointmentId} ")
    Appointment getAppointmentById(@Param("appointmentId") String appointmentId);


    @Select("select * from crj_appointment t where (t.id_number = #{idNumber} or t.apply_user_id = #{idNumber}) and t.day_id= #{dayId} and time_period = #{timePeriod} and state in ('1','2') and service_type = #{serviceType}")
//    @Select("select * from crj_appointment t where (t.id_number = #{idNumber} or t.apply_user_id = #{idNumber}) and state in ('1','2') and service_type = #{serviceType}")
    List<Appointment> getCurrentAppointmentListByIdNumber(@Param("idNumber") String idNumber,@Param("dayId") String dayId,@Param("timePeriod") int timePeriod,@Param("serviceType") String serviceType);


    @Update("update crj_appointment set state = #{state} where appointment_id = #{appointmentId}")
    void updateAppointmentState(@Param("appointmentId") String appointmentId,@Param("state") String state);

    @Update("update crj_appointment set state = #{state} where apply_id = #{applyId}")
    void updateAppointmentStateByApplyId(@Param("applyId") String applyId,@Param("state") String state);

    @Update("update crj_appointment set state = #{state} where apply_user_id = #{applyUserId} and service_type = 'M'")
    void updateGroupAppointmentState(@Param("applyUserId") String applyUserId,@Param("state") String state);



    @Update("update crj_appointment set apply_id = #{applyId} where appointment_id = #{appointmentId}")
    void updateApplyId(@Param("appointmentId") Long appointmentId,@Param("applyId") Long applyId);

}
